﻿using System;
using System.Collections.Generic;
using Citi.RoutineBase;

namespace Citi.GocAttributes.SchedulerUI
{
    public class ApplyRules : IExecutableRoutine
    {
        public IEnumerable<RoutineParameter> Parameters
        {
            get { return null; }
        }

        public void Rollback(ref ICurrentAction currentAction, Dictionary<string, object> parameters)
        {
            
        }

        public void Start(DateTime scheduledDate, ref ICurrentAction currentAction, Dictionary<string, object> parameters)
        {
            currentAction.Description = "Applying rules.";

            new RuleApplication(currentAction).Apply(new DateTime(scheduledDate.Year, scheduledDate.Month, 1));

            currentAction.Description = "Rules successfully applied.";
        }

        public void Stop(ref ICurrentAction currentAction, Dictionary<string, object> parameters)
        {
            
        }
    }

    internal class RuleApplication : Domain.Utils.RuleApplication
    {
        private ICurrentAction currentAction;

        public RuleApplication(ICurrentAction currentAction)
        {
            this.currentAction = currentAction;
        }

        public override void Status(string message)
        {
            currentAction.Description = message;
        }
    }
}
